package com.quickask.operate.data;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

/**
 * Created by Administrator on 2015/9/25.
 */
public class RandomCode {

    private final static char[] code = {
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
    };

    public String getNonCestr() {
        StringBuilder str = new StringBuilder();
        for(int i=0;i<16;i++) {
            str.append(code[(int)(Math.random()*62)]);
        }
        return str.toString();
    }

    public String generateToken() {
        StringBuilder str = new StringBuilder();
        for(int i=0;i<50;i++) {
            str.append(code[(int)(Math.random()*62)]);
        }
        return str.toString();
    }

    public Timestamp generateCurrentTimestamp() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = sdf.format(System.currentTimeMillis());
        return Timestamp.valueOf(date);
    }
}
